<?php
require dirname(__FILE__).'/core/fanwe.php';
$fanwe = &FanweService::instance();
$fanwe->initialize();

$index = intval($_REQUEST['index']);
@set_time_limit(0);
if(function_exists('ini_set'))
    ini_set('max_execution_time',0);

$limit = 500;
$list = FDB::fetchAll('SELECT * FROM '.FDB::table('shop').' ORDER BY shop_id DESC LIMIT '.$index.','.$limit);

if(count($list) == 0)
{
	echo "<h1>更新店铺信息完成</h1>";
	exit;
}

foreach($list as $data)
{
	$shop_id = $data['shop_id'];
    $shop = array();
	$shop['recommend_count'] = FS("Shop")->getShopUserCount($shop_id);
	$temp = array();
	$temp['tags'] = FS("Shop")->getShopTags($shop_id);
	$temp['goods'] = FS("Shop")->getShopGoods($shop_id);
	$shop['data'] = addslashes(serialize($temp));
	FDB::update('shop',$shop,'shop_id = '.$shop_id);

    echo "更新店铺 $data[shop_name] 成功<br/>";
	flush();
	ob_flush();
    usleep(100);
}

echo "<script type=\"text/javascript\">var fun = function(){location.href='update_shop.php?index=".($index + $limit)."&time=".time()."';}; setTimeout(fun,500);</script>"."\r\n";
flush();
ob_flush();
exit;
?>